package com.example.demo.service.impl;

import com.example.demo.mapper.EmptMapper;
import com.example.demo.pojo.emp.Empt;
import com.example.demo.pojo.emp.PageBeen;
import com.example.demo.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmptMapper emptMapper;


    @Override
    public Empt login(String username) {
        Empt login = emptMapper.login(username);
        return login;
    }

    @Transactional(rollbackFor = Exception.class)//spring事务管理
    @Override
    public Boolean addEmpt(Empt user) {
        Boolean aBoolean = emptMapper.addEmpt(user);
        return aBoolean;
    }

    @Override
    public PageBeen listPage(Integer page, Integer size,String username,String name,String gender,String job,Integer depId) {
//        设置分页参数
        PageHelper.startPage(page,size);
//        执行查询
        List<Empt> list = emptMapper.listPage(username,name,gender,job,depId);
        Page<Empt> p = (Page<Empt>) list;
        PageBeen pageBeen = new PageBeen(page,size,p.getTotal(),p.getResult());
        return pageBeen;
    }
}
